package com.sangmo.fts.authority;

import com.sangmo.fts.authority.definitions.ClazzAuthority;
import com.sangmo.fts.authority.definitions.FileUploadAuthority;
import com.sangmo.fts.authority.definitions.TrainingIdRefAuthority;
import com.sangmo.fts.authority.definitions.TeamAuthority;
import com.sangmo.fts.authority.definitions.TrainingAuthority;
import com.sangmo.fts.authority.filters.ClazzMemberFilter;
import com.sangmo.fts.authority.filters.TeammateFilter;
import com.sangmo.fts.basic.model.FileUpload;
import com.sangmo.fts.clazz.model.Clazz;
import com.sangmo.fts.common.authority.AuthorityFilterChain;
import com.sangmo.fts.process.factoring.model.FfContract;
import com.sangmo.fts.process.factoring.model.FfFactoringContract;
import com.sangmo.fts.process.factoring.model.FfLoan;
import com.sangmo.fts.process.factoring.model.FfRepayment;
import com.sangmo.fts.process.factoring.model.FfTransferApply;
import com.sangmo.fts.process.factoring.model.FfWaybill;
import com.sangmo.fts.process.inventory.model.IfContract;
import com.sangmo.fts.process.inventory.model.IfInbound;
import com.sangmo.fts.process.inventory.model.IfLadingBill;
import com.sangmo.fts.process.inventory.model.IfLoan;
import com.sangmo.fts.process.inventory.model.IfOutbound;
import com.sangmo.fts.process.inventory.model.IfRepayment;
import com.sangmo.fts.process.inventory.model.IfStock;
import com.sangmo.fts.process.inventory.model.IfWaybill;
import com.sangmo.fts.process.receivable.model.RpfContract;
import com.sangmo.fts.process.receivable.model.RpfLoan;
import com.sangmo.fts.process.receivable.model.RpfPledgeContract;
import com.sangmo.fts.process.receivable.model.RpfRepayment;
import com.sangmo.fts.process.receivable.model.RpfWaybill;
import com.sangmo.fts.process.storage.model.CsfAgreement;
import com.sangmo.fts.process.storage.model.CsfAssurance;
import com.sangmo.fts.process.storage.model.CsfContract;
import com.sangmo.fts.process.storage.model.CsfDraft;
import com.sangmo.fts.process.storage.model.CsfInbound;
import com.sangmo.fts.process.storage.model.CsfLadingBill;
import com.sangmo.fts.process.storage.model.CsfLoan;
import com.sangmo.fts.process.storage.model.CsfOutbound;
import com.sangmo.fts.process.storage.model.CsfRepayment;
import com.sangmo.fts.process.storage.model.CsfStock;
import com.sangmo.fts.process.storage.model.CsfWaybill;
import com.sangmo.fts.training.model.Team;
import com.sangmo.fts.training.model.Training;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class AuthorityConfig {

    @PostConstruct
    private void init() {
        this.registerAuthority();
        this.registerAuthorityType();
    }

    private void registerAuthority() {
        AuthorityFilterChain.getInstance().register(teammateFilter());
        AuthorityFilterChain.getInstance().register(clazzMemberFilter());

    }


    private void registerAuthorityType() {
        AuthorityFilterChain.getInstance().registerEntity(FileUpload.class, FileUploadAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(Training.class, TrainingAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(Team.class, TeamAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(Clazz.class, ClazzAuthority.class);

        //inventory
        AuthorityFilterChain.getInstance().registerEntity(IfContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfInbound.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfLadingBill.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfLoan.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfOutbound.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfRepayment.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfStock.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(IfWaybill.class, TrainingIdRefAuthority.class);

        //storage
        AuthorityFilterChain.getInstance().registerEntity(CsfAgreement.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfAssurance.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfDraft.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfInbound.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfLadingBill.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfLoan.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfOutbound.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfRepayment.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfStock.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(CsfWaybill.class, TrainingIdRefAuthority.class);

        //receivable
        AuthorityFilterChain.getInstance().registerEntity(RpfContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(RpfWaybill.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(RpfLoan.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(RpfPledgeContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(RpfRepayment.class, TrainingIdRefAuthority.class);

        //factoring
        AuthorityFilterChain.getInstance().registerEntity(FfContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(FfFactoringContract.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(FfLoan.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(FfRepayment.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(FfTransferApply.class, TrainingIdRefAuthority.class);
        AuthorityFilterChain.getInstance().registerEntity(FfWaybill.class, TrainingIdRefAuthority.class);

    }

    @Bean
    public TeammateFilter teammateFilter() {
        return new TeammateFilter();
    }

    @Bean
    public ClazzMemberFilter clazzMemberFilter() {
        return new ClazzMemberFilter();
    }
}
